﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Libs.Content;

public partial class Pages_News_List : System.Web.UI.Page
{
    private int top = 10;

    protected void Page_Load(object sender, EventArgs e)
    {
        List<NewsWeb> list;
        NewsWeb _NewsWeb = new NewsWeb();
        int cateID = 0, newsID = 0;
        if (!NewsUtils.CheckUrl(ref cateID, ref newsID))
        {
            Response.Redirect(Constant.HOME_PATH);
        }

        NewsCategories _Cate = new NewsCategories();
        _Cate = _Cate.Get(cateID);
        hplCate.Text = _Cate.Name;
        Title = _Cate.Name + " - " + Constant.SiteTitle;
        hplCate.NavigateUrl = NewsUtils.CateLink(cateID.ToString(), _Cate.Url, "0");
        list = _NewsWeb.GetList(cateID, newsID, top);

        if (list.Count == 0)
        {
            Response.Redirect(Constant.HOME_PATH);
        }

        rptList.DataSource = list;
        rptList.DataBind();

        if (list.Count == top)
        {
            panelOtherNews.Visible = true;
            _NewsWeb = list[top - 1];
            list = _NewsWeb.GetList(cateID, _NewsWeb.NewsID, top);
            if (list.Count == 0) panelOtherNews.Visible = false;
            rptOtherList.DataSource = list;
            rptOtherList.DataBind();

            if (cateID != 0)
            {
                hplNext.NavigateUrl = NewsUtils.CateLink(cateID.ToString(), _Cate.Url, _NewsWeb.NewsID.ToString());
            }
            else
            {
                hplNext.NavigateUrl = NewsUtils.CateLink("0", _Cate.Url, _NewsWeb.NewsID.ToString());
            }
        }
        else
        {
            
            hplNext.Visible = false;
        }
    }

    protected string GetHtml(string _Title, string _Lead, string _Url, string _ImageUrl, DateTime _PublishedTime)
    {
        string s;
        if (_ImageUrl.Length > 0)
        {
            s = Resources.Html.NewsListImg;
            s = s.Replace("$ImageUrl$", AppUtils.ImageUrl(_ImageUrl, "310", "194"));
        }
        else
        {
            s = Resources.Html.NewsList;
        }
        s = s.Replace("$Link$", _Url);
        s = s.Replace("$Title$", _Title);
        s = s.Replace("$Lead$", _Lead);
        s = s.Replace("$Time$", _PublishedTime.ToString("dd/MM/yyyy"));
        return s;
    }
}